<template>
  <div>
    <el-card class="search-card">
      <BasicForm
        ref="formData"
        :hasQueryPermission="false"
        :formColumns="formItems"
        :dataSource="formData"
        :handleSearchForm="handleQueryForm"
        @getFormData="getFormData"
      />
    </el-card>
    <el-card class="table-card">
      <SkusTable
        showPagination
        :tableHeight="480"
        :defaultMinWidth="100"
        :dataSource="TableInfo.list"
        :columns="TableInfo.columns"
        :loading="TableInfo.loading"
        :pageSizes="pageSizes"
        :pagination="pagination"
        :total="pagination.total"
        @pageChange="handlePageChange"
        @pageSizeSelect="handlePageSizeChange"
      />
    </el-card>
  </div>
</template>
<script>
import BasicForm from '@/components/BasicForm';
import SkusTable from '@/components/skusTable';
import skusPage from '@/mixins/commodity/skusPage';
import { FORM_ITEMS, TABLE_COLUMNS } from './constants/clueAndLatentProduct';
import { getInitFormData, TableInfo } from '@/utils/getUtils';
import { setAuthBtnId } from '@/utils/bizUtils';
import { hisListService } from '@/api/finance/salePriceManage/changePriceRecordQuery';
import { queryAreaInfoService } from '@/api/public';
export default {
  mixins: [skusPage],
  components: {
    BasicForm,
    SkusTable,
  },
  data () {
    return {
      formItems: FORM_ITEMS,
      formData: getInitFormData(FORM_ITEMS),
      TableInfo: new TableInfo({ columns: TABLE_COLUMNS }),
      pageSizes: [10, 100, 1000],
    }
  },
  created () {
    this.setProvinceOptions()
    this.getTableData()
  },
  methods: {
    // 获取表格数据
    async getTableData () {
      setAuthBtnId('查询')
      const data = { ...this.formData, ...this.paginationParams }
      const res = await hisListService(data, this.TableInfo.setLoading)
      this.TableInfo.setList(res.retData?.results)
      this.setTotalNum(res.retData?.totalNum)
    },
    // 获取省份下拉集合
    async setProvinceOptions () {
      const res = await queryAreaInfoService()
      const areaInfos = res?.retData ?? []
      const provinceOptions = areaInfos.map(item => ({
        value: item.provinceCode,
        label: item.provinceName
      }))
      const index = this.formItems.findIndex(item => item.prop == 'provinceCode')
      if (index > -1) this.formItems[index].options = provinceOptions
    },
  }
}
</script>
